//
//  HomeView.m
//  YTwallet
//
//  Created by ZhangLin on 2019/2/25.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "HomeView.h"
#import <Masonry.h>


@implementation HomeView


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupViews];
    }
    return self;
}

-(void)setupViews{
    self.backgroundColor = [UIColor colorWithRed:242 / 255.0 green:244 / 255.0 blue:246 / 255.0 alpha:1.0];
    
    self.topView = [[UIView alloc] init];
    self.topView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.height.equalTo(self).multipliedBy(0.18);
    }];
    
    
    self.swipeCardImv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"billSelect"]];
    [self.topView addSubview:self.swipeCardImv];
    
    self.creditCardImv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_bg_xinyongka"]];
    [self.topView addSubview:self.creditCardImv];
    
    
    
    NSMutableArray *array = [NSMutableArray array];
    [array addObject:self.swipeCardImv];
    [array addObject:self.creditCardImv];
    [array mas_distributeViewsAlongAxis:(MASAxisTypeHorizontal) withFixedSpacing:15 leadSpacing:15 tailSpacing:15];
    [array mas_makeConstraints:^(MASConstraintMaker *make) {
        //设置图片宽高比，保证图片不会变形
        make.height.equalTo(self.creditCardImv.mas_width).multipliedBy(0.71);
        //如果手机是X以上
        if ([[UIApplication sharedApplication] keyWindow].frame.size.height >= 812) {
            make.centerY.equalTo(self.topView).offset(16);
        }else
        {
            make.centerY.equalTo(self.topView).offset(10);
        }
    }];
     
    
     
    
    
    self.swipeCardLab = [[UILabel alloc] init];
    self.swipeCardLab.textColor = [UIColor whiteColor];
    self.swipeCardLab.font = [UIFont boldSystemFontOfSize:14.0];
//    self.swipeCardLab.text = @"刷卡收款";
    self.swipeCardLab.text = @"账单查询";
    [self.swipeCardImv addSubview:self.swipeCardLab];
    [self.swipeCardLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.equalTo(self.swipeCardImv).offset(-25);
    }];
    
    
    /*
    self.conPosLab = [[UILabel alloc] init];
    self.conPosLab.textColor = [UIColor whiteColor];
    self.conPosLab.font = [UIFont systemFontOfSize:10.0];
    self.conPosLab.text = @"连接POS";
    [self.swipeCardImv addSubview:self.conPosLab];
    [self.conPosLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.swipeCardLab);
        make.centerY.equalTo(self.swipeCardImv);
    }];
     */
     
    
    
    self.creditCardLab = [[UILabel alloc] init];
    self.creditCardLab.textColor = [UIColor whiteColor];
    self.creditCardLab.font = [UIFont boldSystemFontOfSize:14.0];
    self.creditCardLab.text = @"信用卡收款";
    [self.creditCardImv addSubview:self.creditCardLab];
    [self.creditCardLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
         make.centerY.equalTo(self.creditCardImv).offset(-25);
    }];
    
    /*
    self.noPosCardLab = [[UILabel alloc] init];
    self.noPosCardLab.textColor = [UIColor whiteColor];
    self.noPosCardLab.font = [UIFont systemFontOfSize:10.0];
    self.noPosCardLab.text = @"无需POS";
    [self.creditCardImv addSubview:self.noPosCardLab];
    [self.noPosCardLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.creditCardLab);
        make.centerY.equalTo(self.creditCardImv);
    }];
     */
    
    
    self.messageView = [[UIView alloc] init];
    self.messageView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.messageView];
    [self.messageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(44);
        make.top.equalTo(self.topView.mas_bottom).offset(1);
    }];
    
    self.messageImv = [[UIImageView alloc] init];
    self.messageImv.image = [UIImage imageNamed:@"icon_message"];
    [self.messageView addSubview:self.messageImv];
    [self.messageImv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.messageView);
        make.left.equalTo(self.messageView).offset(15);
        make.width.mas_equalTo(16);
        make.height.mas_equalTo(16);
    }];
    
    self.messageLab = [[UILabel alloc] init];
    self.messageLab.textColor = [UIColor whiteColor];
    self.messageLab.font = [UIFont systemFontOfSize:16.0];
    self.messageLab.textAlignment = NSTextAlignmentRight;
    self.messageLab.text = @"消息";
    self.messageLab.textColor = [UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1.0];
    self.messageLab.font = [UIFont boldSystemFontOfSize:14.0];
    [self.messageView addSubview:self.messageLab];
    [self.messageLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.messageImv.mas_right);
        make.centerY.equalTo(self.messageView);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(20);
    }];
    
    self.lineView = [[UIView alloc] init];
    self.lineView.backgroundColor = [UIColor colorWithRed:229 / 255.0 green:229 / 255.0 blue:229 / 255.0 alpha:1.0];
    [self.messageView addSubview:self.lineView];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.messageLab.mas_right).offset(10);
        make.centerY.equalTo(self.messageView);
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(20);
    }];
    
    self.arrowImv = [[UIImageView alloc] init];
    self.arrowImv.image = [UIImage imageNamed:@"icon_arrow_right"];
    [self.messageView addSubview:self.arrowImv];
    [self.arrowImv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.messageView).offset(-15);
        make.centerY.equalTo(self.messageView);
        make.width.mas_equalTo(16);
        make.height.mas_equalTo(16);
    }];
    
    self.pointView = [[UIView alloc] init];
    self.pointView.backgroundColor = ETColorWithRGB(252, 92, 76);
    self.pointView.layer.cornerRadius = 3;
    [self.messageView addSubview:self.pointView];
    [self.pointView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.arrowImv.mas_left).offset(2);
        make.centerY.equalTo(self.messageView);
        make.width.mas_equalTo(6);
        make.height.mas_equalTo(6);
    }];
    
    self.timeLab = [[UILabel alloc] init];
    self.timeLab.text = @"11:24";
    self.timeLab.textColor = [UIColor colorWithRed:153 / 255.0 green:153 / 255.0 blue:153 / 255.0 alpha:1.0];
    self.timeLab.font = [UIFont systemFontOfSize:13.0];
    [self.messageView addSubview:self.timeLab];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.pointView.mas_left).offset(-2);
        make.centerY.equalTo(self.messageView);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(35);
    }];
    
    
    /*
    self.tipslab = [[UILabel alloc] init];
    self.tipslab.text = @"好消息! 费率重新调整，降息0.4%啦啦啦啦啦啦";
    self.tipslab.textColor = [UIColor colorWithRed:55 / 255.0 green:55 / 255.0 blue:55 / 255.0 alpha:1.0];
    self.tipslab.font = [UIFont systemFontOfSize:13.0];
    [self.messageView addSubview:self.tipslab];
    [self.tipslab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lineView).offset(10);
        make.centerY.equalTo(self.messageView);
        make.right.equalTo(self.timeLab.mas_left).offset(-5);
        make.height.mas_equalTo(18);
    }];
     */
    
    self.contentLabel = [[ZScrollLabel alloc] initWithFrame:(CGRectMake(10, 400, self.frame.size.width - 100, 18))];
    self.contentLabel.textColor = [UIColor colorWithRed:55 / 255.0 green:55 / 255.0 blue:55 / 255.0 alpha:1.0];
    self.contentLabel.font = [UIFont systemFontOfSize:13.0];
    self.contentLabel.labelAlignment = ZScrollLabelAlignmentLeft;
    [self.messageView addSubview:self.contentLabel];
    [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lineView).offset(10);
        make.centerY.equalTo(self.messageView);
        make.right.equalTo(self.timeLab.mas_left).offset(-5);
        make.height.mas_equalTo(18);
    }];
    
    

    
    
    
    self.carouselview = [[UIView alloc] init];
    self.carouselview.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.carouselview];
    [self.carouselview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.equalTo(self.messageView.mas_bottom).offset(10);
        make.height.mas_equalTo(110);
    }];
    
    self.financialServiceView = [[UIView alloc] init];
    self.financialServiceView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.financialServiceView];
    [self.financialServiceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.equalTo(self.carouselview.mas_bottom).offset(10);
        make.height.mas_equalTo(222);
    }];
    
    self.financialServiceLab = [[UILabel alloc] init];
    self.financialServiceLab.text = @"金融服务";
    self.financialServiceLab.font = [UIFont boldSystemFontOfSize:16.0];
    self.financialServiceLab.textColor = [UIColor colorWithRed:55 / 255.0 green:55 / 255.0 blue:55 / 255.0 alpha:1];
    [self addSubview:self.financialServiceLab];
    [self.financialServiceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.financialServiceView).offset(15);
        make.top.equalTo(self.financialServiceView).offset(20);
//        make.width.mas_equalTo(64);
        make.height.mas_equalTo(22);
    }];
    
}
    

@end
